package com.three.service.impl;

import com.baor.baseUtil.R;
import com.three.dao.LogsDao;
import com.three.domain.Logs;
import com.three.service.LogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class LogsServiceImpl implements LogsService {
    @Autowired
    private LogsDao logsDao;

    @Override
    public R logsList(Integer id, Integer pageIndex, Integer pageSize) {
        pageIndex = (pageIndex - 1) * pageSize;
        double pageCount = logsDao.PageCount();
        pageCount = Math.ceil(pageCount / pageSize);
        List<Logs> logsList = logsDao.logsList(id,pageIndex, pageSize);
        Map<String, Object> map = new HashMap<>();
        map.put("pageCount", pageCount);
        map.put("logsList", logsList);
        return R.ok(map);
    }

    @Override
    public R addLogs(Logs logs) {
        return R.ok(logsDao.addLogs(logs));
    }





    @Override
    public R LogsListByStudent(Integer pageIndex, Integer pageSize) {
        pageIndex = (pageIndex - 1) * pageSize;
        double pageCountlogs =logsDao.PageCountLogs(pageIndex,pageSize);
        pageCountlogs = Math.ceil(pageCountlogs / pageSize);
        List<Logs> studentsList = logsDao.LogsListByStudent(pageIndex,pageSize);
        Map<String, Object> map = new HashMap<>();
        map.put("pageCountlogs", pageCountlogs);
        map.put("studentsList", studentsList);
        return R.ok(map);
    }
    @Override
    public void updateLog(Logs log) {
        logsDao.updateLog(log);  // 调用 DAO 方法
    }
}
